#cc0 License
# credit :mn , richitaroy, anitaroy
import random
import math
from time import strftime
import urllib.request


#mathematical expressions part

def cbadd(a,b):
    return a+b

def cbmod(a,b): #added this
    return a%b

def minus(a,b):
    return a-b

def cbsqrt(a):
    return math.sqrt(a)

def cbdiv(a,b):
    if type(a) == tuple:
        totalA = 1
        a= list(a)
        for i in range(0,len(a)):
            totalA *= a[i]
            print(a[i])
        return totalA/b
    else:
        return a / b

#end of mathematical expressions part

def cbrange(x):
    return range(1,x+1)

def cbarrayindex(x):
    return range(0,x)

def cbprint(a):
    print(a)

def cbint(a):
    return int(a)

def cbtostring(a):
    if type(a) == int or type(a) == float :
        return str(a)
    else : pass

def cbisEqual(a,b):
    return a==b

def cbpow(a,pow):
    return a**pow

def cbinput():
    return input()

def cbrandint(x,y):
    return random.randint(x,y)

def cbcompare(s1,s2):
    for i in cbarrayindex(len(s1) - 1):
        if (s1[i] != s2[i]):
            news1 = cbsubstring(s1,i,i+1) ;  news2 = s2[i:(i+1)]; '''  checked cbsubstring to see if it works or not.
              Actually java has a function called compareTo which does the same thing(find the difference of the 
              first two alphabets of the words), its like s1.compareTo(s2)'''
            asciis1 = cbascii(news1)
            asciis2 = cbascii(news2)
            difference = asciis1 - asciis2
            return difference
            break


def cbascii(a):
    from sys import stdout
    f = ""
    count = 1
    for tc in a:
        if f == "-h":
            stdout.write(hex(ord(tc)).replace("0x", ""))
        else:
            stdout.write(str(ord(tc)))
        if count > 7:
            count = 0
            stdout.write(chr(32))
            stdout.write(" ")
            count += 1
        print("")

def cbsubstring(s,start,end):
    return(s[start:end])

def cb1stIO(s, alphbt): #fullform 1st Index Of
    if len(s) > 1 :
        for i in cbarrayindex(len(s)):
            if s[i:i+1] == alphbt:
                return i
                break

def cbLastIO(s, alphbt): #fullform Last Index Of
    if len(s) > 1 :
        for i in cbarrayindex(len(s)):
            if s[-(i+1):-i] == alphbt:
                return i
                break

def cblc(a): #lowercase
    return a.lower()

def cbuc(a): #Uppercase
    return a.upper()

####The new stuff

def cbleft(a,b):
    return a[:b]

def cbright(a,b):
    return a[-b:]

def cbifpresent(s, alphbt):
    if len(s) > 0 and type(s) == str :
        for i in range(1,len(s)):
            if s[i] == alphbt:
                return True
    elif len(s)>0 and isinstance(s,list)== True :
        for i in range(0,len(s)-1):
            if s[i] == alphbt:
                return True

def cbtan(a):
    return math.tan(a)

def cbsin(a):
    return math.sin(a)

def cbcos(a):
    return math.cos(a)

def cbhex(a):
    return hex(a)

def cboct(a):
    return oct(a)

def cbmodulus(a):
    if a<0 :
        return a*-1
    if a>0:
        return a

def date():
    return strftime("%d/%m/%y")

def cbclearWS(a):
    return a.replace(" ", "")

def cbftoc(a):
    tempF = (a*1.8) + 32
    return tempF

def cbctof(a) :
    tempC  = (a-32)/1.8
    return tempC

def cbreversestr(a):
    return a[::-1]

def reverselist(a):
    return a.cbreverse()

def cbternary(condition, truevalue , falsevalue):

    if condition == True:
        return truevalue
    else:
        return falsevalue

def cbfileWrite(filename, content):
    file = filename
    with open(file,"w")as f :
        f.write(content)
        f.close()

def cbfileRead(filename):
    file = filename
    with open(file,"r")as f :
        text = f.read()
        return text

def cbshell(command):
    import subprocess
    subprocess.call(command, shell=True)

def cbifless(a,b):
    return a<b

def cbifmore(a,b):
    return a>b

def cbbitostr(string):
    s=""
    for i in string.split():
        s += chr(int("0b" + i, base=2))
    return s

def cbum(file):
    umstr = ""
    fr = cbfileRead(file)
    for p in fr.split("."):
        umstr += p + " umm... \n"

    return umstr

def cbimage(url):
    name = random.randint(1,100)
    fullname = str(name) + ".jpg"
    urllib.request.urlretrieve(url,fullname)

def cbcolor(text,color): #color can be RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
    from colorama import Fore, Back, Style
    if color == "red" or color =="Red" :
        return (Fore.RED + text)
    if color == "blue" or color =="Blue" :
        return (Fore.BLUE + text)
    if color == "yellow" or color =="Yellow" :
        return (Fore.YELLOW + text)
    if color == "cyan" or color =="Cyan" :
        return (Fore.CYAN + text)



